package com.stream;

import java.util.ArrayList;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/*
    Straem流的收集操作
        collect(Collectors.toList())
        collect(Collectors.toSet())
        collect(Collectors.toMap())
 */
public class StreamCollect {
    public static void main(String[] args) {
        ArrayList<String> list=new ArrayList<>();
        list.add("张三,24");
        list.add("李四,25");
        list.add("王五,26");
        // 保留年龄大于24，收集到Map集合，姓名为建，年龄为值
        Map<String, Integer> map = list.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return Integer.parseInt(s.split(",")[1]) > 24;
            }
        }).collect(Collectors.toMap(new Function<String, String>() {
            @Override
            public String apply(String s) {
                return s.split(",")[0];
            }
        }, new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return Integer.parseInt(s.split(",")[1]);
            }
        }));
        System.out.println(map);
    }
}
